package com.example.jwts.controller;

import com.example.jwts.utils.R;
import com.example.jwts.utils.BaseUserInfo;
import com.example.jwts.enu.UserInfoEnu;
import com.example.jwts.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class testController {


    /**
     * 获得用户信息
     *
     * @return
     */
    @PostMapping("test")
    public String getBaseUserInfo() {
        String name = BaseUserInfo.get(UserInfoEnu.user.getCode());
        String pass = BaseUserInfo.get(UserInfoEnu.pass.getCode());
        return "name:" + name + "-----pass:" + pass;
    }

    /**
     * 模拟用户登录
     *
     * @param name
     * @param pass
     * @return
     */
    @GetMapping("/login")
    public Map login(String name, String pass) {
        Map<String, String> map = new HashMap<>();
        map.put("name", name);
        map.put("pass", pass);
        String token = JWTUtils.getToken(map);
        return R.succeed(200, "登录成功", token);
    }

}
